//
//  MessageNotificationView.m
//  SZBank
//
//  Created by rimi on 16/7/20.
//  Copyright © 2016年 LuoYao. All rights reserved.
//

#import "MessageNotificationView.h"
#define MYCOLOR [UIColor colorWithRed:0.227 green:0.349 blue:0.078 alpha:1.000]
@interface MessageNotificationView()
{
    CGFloat frameWidth;/**  自身宽度 */
    CGFloat frameHeight;/**  自身高度 */
    UIButton *leftButton;/**  左侧按钮 */
    UIButton *rightButton;/**  右侧按钮 */
    NSMutableArray *titleArray;/**  按钮标题数组 */
    NSMutableArray *contentArray;/**  按钮标题内容数组 */
}
@property (nonatomic,strong) UIImageView *bgImageView;/**  背景图 */

@property (nonatomic,strong) UIWebView *webView;
@end
@implementation MessageNotificationView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        frameWidth = self.frame.size.width;
        frameHeight = self.frame.size.height;
        [self addSubview:self.bgImageView];
        titleArray = [NSMutableArray array];
        contentArray = [NSMutableArray array];
        /**  短信通知数据请求*/
        [NetWorkingDataManager getProtocolTemplateUpdateWithProtocolid:@"402881e540a3933d0140a40f636f0001" success:^(id sender) {
            
            [titleArray addObject:[sender[0] objectForKey:@"attributeOrder"][0]];
            [titleArray addObject:[sender[0] objectForKey:@"attributeOrder"][1]];
            NSDictionary *dic = [sender[0] objectForKey:@"protocolData"];
            [contentArray addObject:[dic objectForKey:@"开通方式"][0]];
            [contentArray addObject:[dic objectForKey:@"收费标准"][0]];
            [self initUserInterface];
        } failure:nil];
    }
    return self;
}

- (void)initUserInterface{
    /**  左按钮 */
    leftButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, frameWidth * 0.5, frameHeight * 0.08)];
    [self getButton:leftButton image:@"短信通知0_03" textColor:[UIColor whiteColor] title:titleArray[0]];
    [leftButton addTarget:self action:@selector(action_leftButton) forControlEvents:UIControlEventTouchUpInside];
    /**  右按钮 */
    rightButton = [[UIButton alloc] initWithFrame:CGRectMake(frameWidth * 0.5, 0, frameWidth * 0.5, frameHeight * 0.08)];
    [self getButton:rightButton image:@"短信通知_04" textColor:MYCOLOR title:titleArray[1]];
    [rightButton addTarget:self action:@selector(action_rightButton) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:leftButton];
    [self addSubview:rightButton];
    /**  初始化显示 */
    [self.webView loadHTMLString:contentArray[0] baseURL:nil];
    [self addSubview:self.webView];
}
#pragma mark -- 按钮点击事件
- (void)action_leftButton{
    /**  左按钮 */
    [self getButton:leftButton image:@"短信通知0_03" textColor:[UIColor whiteColor] title:titleArray[0]];
    /**  右按钮 */
    [self getButton:rightButton image:@"短信通知_04" textColor:MYCOLOR title:titleArray[1]];
    /**  内容显示 */
    [self.webView loadHTMLString:contentArray[0] baseURL:nil];
    [self addSubview:self.webView];
}

- (void)action_rightButton{
    /**  左按钮 */
    [self getButton:leftButton image:@"短信通知_03" textColor:MYCOLOR title:titleArray[0]];
    /**  右按钮 */
    [self getButton:rightButton image:@"短信通知0_04" textColor:[UIColor whiteColor] title:titleArray[1]];
    /**  内容显示 */
    [self.webView loadHTMLString:contentArray[1] baseURL:nil];
    [self addSubview:self.webView];
}
/**  按钮属性方法 */
- (void)getButton:(UIButton *)button image:(NSString *)image textColor:(UIColor *)textColor title:(NSString *)title{
    [button setBackgroundImage:[LocalDataManager getImageWithSourceOfPath:image] forState:UIControlStateNormal];
    [button setTitleColor:textColor forState:UIControlStateNormal];
    [button setTitle:title forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:28];
}

- (UIImageView *)bgImageView{
    if (!_bgImageView) {
        _bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, frameWidth, frameHeight)];
        _bgImageView.image = [LocalDataManager getImageWithSourceOfPath:@"通用背景"];
    }
    return _bgImageView;
}

- (UIWebView *)webView{
    if (!_webView) {
        _webView = [[UIWebView alloc] initWithFrame:CGRectMake(frameWidth * 0.01, frameHeight * 0.1, frameWidth * 0.9, frameHeight * 0.5)];
        
        _webView.dataDetectorTypes = UIDataDetectorTypeAll;
        _webView.backgroundColor = [UIColor clearColor];
        [_webView setOpaque:NO];
    }
    return _webView;
}
@end
